﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using FisheryPlatform.SiteConfig;
using System.Data.SqlClient;
using System.Text;

namespace FisheryPlatform.Web.Admin
{
    public partial class Demo : System.Web.UI.Page
    {
        protected long sqlTime = 0;
        protected long sqlCount = 0;
        Stopwatch pageTimer = new Stopwatch();

        protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);
            pageTimer.Start();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            #region
            Stopwatch timer = new Stopwatch();
            timer.Start();
            using (SqlConnection conn = new SqlConnection(SiteConfigManager.DatabaseSettings["DBConnString"].ConnectionString))
            {
                conn.Open();
                SqlCommand comm = new SqlCommand("Products_Search", conn);
                comm.CommandType = System.Data.CommandType.StoredProcedure;
                comm.Parameters.Add(new SqlParameter { ParameterName = "@sqlWhere", SqlValue = "1=1" });
                comm.Parameters.Add(new SqlParameter { ParameterName = "@pageIndex", SqlValue = 1 });
                comm.Parameters.Add(new SqlParameter { ParameterName = "@pageSize", SqlValue = 1000 });
                comm.Parameters.Add(new SqlParameter { ParameterName = "@pageCount", SqlValue = 0 });
                SqlDataReader reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    sqlCount++;
                }
                conn.Close();
            }
            timer.Stop();
            sqlTime = timer.ElapsedMilliseconds;
            #endregion
        }

        protected override void OnPreRender(EventArgs e)
        {
            #region
            base.OnPreRender(e);

            pageTimer.Stop();
            StringBuilder sb = new StringBuilder();
            Response.Write("page time:" + pageTimer.ElapsedMilliseconds);
            Response.Write("<br/>");
            Response.Write("Product条数：" + sqlCount.ToString() + " 执行时间" + sqlTime.ToString() + "/MS");
            Response.End();
            #endregion
        }
    }
}